<?php
PageUtil::addVar("javascript_body","
                                    <script>
                                          $('.image-popover').popover({trigger: 'hover', html: true, delay: 2});
                                    </script>
                                    ");

foreach($posts as $post) {
          if(!empty($post['meta']['home']) AND $post['meta']['home'] == 1){
      ?>
          <div class="item-list item-list-home-sell">
          <?php }else{ ?>
          <div class="item-list">
          <?php }
          if($post["type"]["id"] == 9){
            ?>
            <div class="sole-stamp">
            </div>
            <?php
          }
          ?>

          <a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank">
            <div class="github-fork-ribbon-wrapper right">
              <div class="github-fork-ribbon">
          <?php
          if(!empty($post['meta']['home']) AND $post['meta']['home'] == 1){
          ?>
            <img src="<?php echo $imagepath."/icon_home.png";?>" alt="ประกาศนี้เจ้าของขายเอง" title="ประกาศนี้เจ้าของขายเอง">
          <?php
          }
          ?>
          <?php
          if(!empty($post["group"]) AND ($post["group"] == 2 OR $post["group"] == 6)){
          ?>
            <img src="<?php echo $imagepath."/icon_confirm.png";?>" alt="ประกาศนี้ได้รับการยืนยันตัวตนแล้ว" title="ประกาศนี้ได้รับการยืนยันตัวตนแล้ว">
          <?php
          }
          ?>
          <?php
          if(!empty($post["group"]) AND $post["group"] == 6){
          ?>
            <img src="<?php echo $imagepath."/icon_tent.png"?>" width="16" alt="ประกาศจากเต้นท์รถ" title="ประกาศจากเต้นท์รถ">
          <?php
          }
          ?>
              </div>
            </div>
          </a>

              <div class="image-block">
                <?php if(!empty($post["images"])){
                  foreach( $post["images"]  as $img) :
                    if($img['firstimage'] == 1){
                ?>
                      <a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank" class="image-popover" rel="popover" data-content="<img src='<?php echo base_url($img["medium"]);?>'>" title=""><img class="thumbnail-post" src="<?php echo base_url($img["small"]);?>" alt="<?php echo $post['title']; ?>"></a>
                <?php
                    }
                 endforeach;
                }else{
                ?>
                  <a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank"><a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank"><img class="thumbnail-post" src="<?php echo $imagepath."/not_available.jpg";?>" alt="<?php echo $post['title']; ?>"></a></a>
                <?php
                }
                ?>
              </div>
              <div class="detail-block">
                <h3><a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank"><?php echo $post['title']; ?></a></h3>
                <h4><?php echo mb_substr((strip_tags($post['content'])), 0, 200); ?></h4>
                <span class="post-title">หมวดหมู่: 
                  <?php 
                  $urlCat = array();
                  foreach ($post["categories"] as $catKey => $catValue) {
                    $urlCat[] = $catValue["url"];
                    echo "<a href=\"".base_url("category/".implode("/", $urlCat))."\"  target=\"_blank\">".$catValue["name"]."</a>";
                    if($catKey < (count($post["categories"])-1)){
                      echo " &raquo; ";
                    }
                  }
                  ?>
                </span>
                <span class="post-contact post-contact-name">
                  <?php
                  if($post["group"] == 6){
                    $icon_post = "<img src=\"".$imagepath."/icon_tent.png\" alt=\"ชื่อเต้นท์\" />";
                    $pre_name = "เต้นท์ ";
                  }else{
                    $icon_post = "<img src=\"".$imagepath."/icon_user.png\" alt=\"ชื่อผู้ใช้\" />";
                    $pre_name = "คุณ ";
                  }
                  ?>
                  <?php echo $icon_post;?>
                  <a href="<?php echo base_url('post/user/'.$post['username']); ?>" ><?php if($post['username'] != "truck.co.th"){ echo $pre_name; } echo $post["firstname"]." ".$post['lastname']; ?></a>
                </span>
                <span class="post-contact"><img src="<?php echo $imagepath."/icon_phone.png"?>" alt="เบอร์โทรศัพท์"  /> <?php echo substr($post['mobile'], 0, 3)."-".substr($post['mobile'], 3, 3)."-".substr($post['mobile'],6); ?></span>
                <span class="post-contact"><img src="<?php echo $imagepath."/icon_pin.png"?>" alt="จังหวัด"  /> <?php echo $post['province']; ?></span>
              </div>
              <a href="<?php echo base_url('post/view/'.$post['url']); ?>" target="_blank">
              <div class="price-block">

                <span class="post-price"><?php echo $post["type"]["name"]."<br />".number_format(intval($post["meta"]["price"]), 0, '.', ','); ?></span>
              </div></a>
              <span class="post-date"><img src="<?php echo $imagepath."/icon-calendar.png"?>" alt="วันที่ <?php echo $post['cr_date']; ?>"/> <?php echo Util::ezDate($post['cr_date']); ?></span>
              <span class="post-view-comment"><img src="<?php echo $imagepath."/icon_views.png"?>" alt="จำนวนคนดู <?php echo $post['view']; ?>"/> <?php echo $post['view']; ?> &nbsp;&nbsp; <img src="<?php echo $imagepath."/icon_comment.gif"?>" alt="จำนวนความคิดเห็น <?php echo $post['comment_count']; ?>"/> <?php echo $post['comment_count']; ?></span>
              <div class="clear"></div>
            </div>
          <?php
          } // End foreach
          ?>